{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "tf.Tensor(\n",
      "[1 1 1 1 0 1 0 1 1 1 0 1 1 1 1 1 1 0 1 1 1 0 1 1 0 1 1 1 0 1 1 0 1 1 1 1 1\n",
      " 0 1 1 1 1 0 1 1 1 1 1 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 0 1 1 0 0 1 1 1 0\n",
      " 0 0 1 1 1 1 0 1 0 1 0 0 0 1 0 0 1 0 0 0 1 0 1 1 1 0 0 1 0 1 0 0 0 0 0 0 1\n",
      " 1 1 1 1 1 1 1 1 1 0 1 1 1 1 0 0 1], shape=(128,), dtype=int32)\n",
      "tf.Tensor(\n",
      "[1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1\n",
      " 1 1 1 1 1 1 1 1 1 1 1 0 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n",
      " 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n",
      " 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1], shape=(128,), dtype=int64)\n",
      "loss:0.662921; acc:0.679688\n",
      "tf.Tensor(\n",
      "[1 1 1 0 1 0 1 1 1 1 0 1 1 0 1 1 1 0 1 0 1 1 1 0 0 1 0 1 1 0 1 1 0 1 1 1 1\n",
      " 1 1 0 0 0 1 1 1 0 1 1 0 0 0 1 1 0 1 1 0 1 1 1 1 1 1 1 0 0 1 1 0 1 1 1 1 1\n",
      " 0 1 0 1 1 1 0 1 0 1 1 1 0 1 1 1 1 1 0 1 0 1 0 1 1 0 1 1 1 1 0 1 1 1 0 0 0\n",
      " 0 1 1 1 1 0 1 1 0 1 0 1 1 1 1 1 1], shape=(128,), dtype=int32)\n",
      "tf.Tensor(\n",
      "[1 1 1 0 1 0 1 1 1 1 0 1 1 0 1 1 1 0 1 0 1 1 1 0 0 1 0 1 1 0 1 1 0 1 1 1 1\n",
      " 1 1 0 1 0 1 1 1 0 1 1 0 0 0 1 1 0 1 1 0 1 1 1 1 1 1 1 0 0 1 1 0 1 1 1 1 1\n",
      " 1 1 0 1 1 1 0 1 0 1 1 1 0 1 1 1 1 1 0 1 0 1 0 1 1 0 1 1 1 1 1 1 1 1 0 0 0\n",
      " 0 1 1 1 1 1 1 1 0 1 0 1 1 1 1 1 1], shape=(128,), dtype=int64)\n",
      "loss:0.624686; acc:0.968750\n",
      "tf.Tensor(\n",
      "[0 1 1 0 0 0 0 1 0 0 1 0 1 1 0 1 1 0 0 0 0 0 1 0 1 1 1 1 1 0 0 0 0 1 0 1 1\n",
      " 0 1 1 1 1 1 0 0 1 1 1 1 1 1 1 1 1 1 0 1 1 0 0 0 1 0 0 1 0 0 1 1 1 1 1 0 0\n",
      " 0 1 1 1 0 1 1 0 1 0 1 1 1 0 1 1 1 1 1 0 1 1 0 1 1 1 1 0 1 0 0 1 1 1 1 0 1\n",
      " 0 1 0 1 0 1 1 1 1 0 1 1 1 1 1 1 0], shape=(128,), dtype=int32)\n",
      "tf.Tensor(\n",
      "[0 1 1 0 0 0 1 1 0 0 1 0 1 1 0 1 1 0 0 0 0 0 1 0 1 1 1 1 1 0 0 0 0 1 0 1 1\n",
      " 0 1 1 1 1 1 0 0 1 1 1 1 1 1 1 1 1 1 0 1 1 0 0 0 1 0 0 1 0 0 1 1 1 1 1 0 0\n",
      " 0 1 1 1 0 1 1 0 1 0 1 1 1 0 1 1 1 1 1 0 1 1 0 1 1 1 1 0 1 0 0 1 1 1 1 0 1\n",
      " 0 1 0 1 0 1 1 1 1 0 1 1 1 1 1 1 0], shape=(128,), dtype=int64)\n",
      "loss:0.582476; acc:0.992188\n",
      "tf.Tensor(\n",
      "[0 1 0 0 1 0 1 0 1 0 1 0 1 0 1 1 0 1 1 1 1 0 1 1 1 1 0 0 0 1 0 1 1 1 1 0 0\n",
      " 0 0 1 0 0 0 1 1 0 1 0 0 1 1 1 1 0 1 1 1 1 0 0 0 1 1 0 0 0 1 0 1 0 1 0 1 1\n",
      " 1 0 1 1 1 1 1 0 1 1 1 1 0 1 0 1 1 1 1 0 1 0 1 0 0 1 1 0 1 0 1 1 0 1 1 1 1\n",
      " 0 0 1 1 0 0 1 1 0 0 1 0 1 0 0 0 1], shape=(128,), dtype=int32)\n",
      "tf.Tensor(\n",
      "[0 1 0 0 1 0 1 0 1 0 1 0 1 0 1 1 0 1 1 1 1 0 1 1 1 1 0 0 0 1 0 1 1 1 1 0 0\n",
      " 0 0 1 0 0 0 1 1 0 1 0 0 1 1 1 1 0 1 1 1 1 0 0 0 1 1 0 0 0 1 0 1 0 1 0 1 1\n",
      " 1 0 1 1 1 1 1 0 1 1 1 1 0 1 0 1 1 1 1 0 1 0 1 0 1 1 1 0 1 0 1 1 0 1 1 1 1\n",
      " 0 0 1 1 0 0 1 1 0 0 1 0 1 0 0 0 1], shape=(128,), dtype=int64)\n",
      "loss:0.543294; acc:0.992188\n",
      "tf.Tensor(\n",
      "[0 1 1 0 0 0 1 1 1 0 1 1 1 1 1 1 1 0 1 0 1 1 1 1 0 0 0 0 0 0 1 1 1 1 1 0 1\n",
      " 1 0 1 0 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 1 1 0 0 0 0 1 1 1 1 0 0 1 1 0 1 0 1\n",
      " 1 0 0 1 0 0 0 1 1 0 1 1 1 1 1 0 0 1 0 0 1 1 0 0 0 1 1 0 0 1 0 0 1 1 1 0 0\n",
      " 1 0 0 1 0 1 1 1 1 1 1 1 1 0 0 0 0], shape=(128,), dtype=int32)\n",
      "tf.Tensor(\n",
      "[0 1 1 0 0 0 1 1 1 0 1 1 1 1 1 1 1 0 1 0 1 1 1 1 0 0 0 0 0 0 1 1 1 1 1 0 1\n",
      " 1 0 1 0 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 1 1 0 0 0 0 1 1 1 1 0 0 1 1 0 1 0 1\n",
      " 1 0 0 1 0 0 0 1 1 0 1 1 1 1 1 0 0 1 0 0 1 1 0 0 0 1 1 0 0 1 0 0 1 1 1 0 0\n",
      " 1 0 0 1 0 1 1 1 1 1 1 1 1 0 0 0 0], shape=(128,), dtype=int64)\n",
      "loss:0.483259; acc:1.000000\n",
      "tf.Tensor(\n",
      "[0 1 0 1 1 1 0 1 0 1 1 1 1 0 0 1 0 1 1 0 0 1 0 0 1 1 0 1 0 1 0 1 1 0 0 1 1\n",
      " 1 0 1 1 0 1 0 1 0 0 1 0 0 1 1 1 1 1 1 0 1 0 0 1 0 1 0 1 1 0 0 1 1 1 0 1 1\n",
      " 0 0 0 0 0 1 1 0 0 0 1 0 0 0 1 1 0 0 0 1 1 0 0 0 0 1 0 0 1 0 1 1 1 0 1 0 0\n",
      " 1 1 1 0 0 1 0 1 0 1 0 0 0 1 0 1 1], shape=(128,), dtype=int32)\n",
      "tf.Tensor(\n",
      "[0 1 0 1 1 1 0 1 0 1 1 1 1 0 0 1 0 1 1 0 0 1 0 0 1 1 0 1 0 1 0 1 1 0 0 1 1\n",
      " 1 0 1 1 0 1 0 1 0 0 1 0 0 1 1 1 1 1 1 0 1 0 0 1 0 1 0 1 1 0 0 1 1 1 0 1 1\n",
      " 0 0 0 0 0 1 1 0 0 0 1 0 0 0 1 1 0 0 0 1 1 0 0 0 0 1 0 0 1 0 1 1 1 0 1 0 0\n",
      " 1 1 1 0 0 1 0 1 0 1 0 0 0 1 0 1 1], shape=(128,), dtype=int64)\n",
      "loss:0.434669; acc:1.000000\n",
      "tf.Tensor(\n",
      "[1 0 1 0 0 1 1 1 1 1 1 1 1 0 1 0 1 0 1 1 1 1 1 1 1 0 0 1 1 0 1 1 1 1 1 1 1\n",
      " 1 1 1 0 1 0 1 0 0 1 1 1 1 0 1 1 1 1 1 0 1 1 0 1 1 1 1 1 1 1 0 1 1 1 0 1 1\n",
      " 1 1 1 1 1 1 1 1 0 1 1 0 1 0 1 1 1 0 0 1 1 0 1 1 1 0 1 0 1 1 1 0 0 1 1 0 1\n",
      " 1 1 1 0 1 0 0 1 1 0 1 1 0 1 1 0 1], shape=(128,), dtype=int32)\n",
      "tf.Tensor(\n",
      "[1 0 1 0 0 1 1 1 1 1 1 1 1 0 1 0 1 0 1 1 1 1 1 1 1 0 0 1 1 0 1 1 1 1 1 1 1\n",
      " 1 1 1 0 1 0 1 0 0 1 1 1 1 0 1 1 1 1 1 0 1 1 0 1 1 1 1 1 1 1 0 1 1 1 0 1 1\n",
      " 1 1 1 1 1 1 1 1 0 1 1 0 1 0 1 1 1 0 0 1 1 0 1 1 1 0 1 0 1 1 1 0 0 1 1 0 1\n",
      " 1 1 1 0 1 0 0 1 1 0 1 1 0 1 1 0 1], shape=(128,), dtype=int64)\n",
      "loss:0.385309; acc:1.000000\n",
      "tf.Tensor(\n",
      "[1 0 0 1 0 1 1 1 0 0 1 1 1 1 1 1 0 0 1 1 1 1 1 1 1 0 0 0 1 1 1 1 1 0 1 1 1\n",
      " 1 0 1 0 1 1 1 1 1 0 0 0 1 1 1 0 1 0 1 1 1 0 1 1 1 1 0 1 1 1 0 1 1 0 1 1 1\n",
      " 1 1 1 1 0 1 1 1 0 1 1 0 1 1 0 1 1 1 1 0 1 1 0 1 0 1 0 1 1 0 0 1 1 1 1 1 1\n",
      " 1 1 0 1 1 0 1 1 1 0 0 1 1 1 1 1 1], shape=(128,), dtype=int32)\n",
      "tf.Tensor(\n",
      "[1 1 0 1 0 1 1 1 0 0 1 1 1 1 1 1 0 0 1 1 1 1 1 1 1 0 0 0 1 1 1 1 1 0 1 1 1\n",
      " 1 0 1 0 1 1 1 1 1 0 0 0 1 1 1 0 1 0 1 1 1 0 1 1 1 1 0 1 1 1 0 1 1 0 1 1 1\n",
      " 1 1 1 1 0 1 1 1 0 1 1 0 1 1 0 1 1 1 1 0 1 1 0 1 0 1 0 1 1 0 0 1 1 1 1 1 1\n",
      " 1 1 0 1 1 0 1 1 1 0 0 1 1 1 1 1 1], shape=(128,), dtype=int64)\n",
      "loss:0.370067; acc:0.992188\n",
      "tf.Tensor(\n",
      "[0 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 1 1 1 0 0 1 0 0 1 1 1 1 1 1 1 0 1 0\n",
      " 1 0 1 1 0 1 0 1 1 0 1 1 0 1 1 0 1 1 0 0 1 1 1 1 0 0 1 0 1 1 1 1 1 1 1 1 0\n",
      " 1 1 0 0 0 1 1 0 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 0 0 1 1 1 1 0 1 0 1 1 1 1 0\n",
      " 0 1 1 1 1 1 1 0 1 1 1 1 1 0 1 1 1], shape=(128,), dtype=int32)\n",
      "tf.Tensor(\n",
      "[0 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 1 1 1 0 0 1 0 0 1 1 1 1 1 1 1 0 1 0\n",
      " 1 0 1 1 0 1 0 1 1 0 1 1 0 1 1 0 1 1 0 0 1 1 1 1 0 0 1 0 1 1 1 1 1 1 1 1 0\n",
      " 1 1 0 0 0 1 1 0 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 0 0 1 1 1 1 0 1 0 1 1 1 1 0\n",
      " 0 1 1 1 1 1 1 0 1 1 1 1 1 0 1 1 1], shape=(128,), dtype=int64)\n",
      "loss:0.355207; acc:1.000000\n",
      "tf.Tensor(\n",
      "[1 1 1 0 0 1 1 1 0 0 1 1 0 1 1 1 0 1 1 0 1 0 0 1 1 0 1 0 1 0 1 1 1 0 0 0 1\n",
      " 0 0 1 0 1 0 1 1 1 1 0 0 1 0 1 1 0 0 1 0 1 1 0 1 0 0 1 0 1 1 1 0 0 1 0 1 1\n",
      " 1 0 1 0 1 1 1 1 1 0 1 0 1 1 1 1 0 0 0 0 1 0 1 0 0 1 0 1 1 1 1 1 0 1 1 0 0\n",
      " 0 1 0 0 1 1 0 1 0 1 0 0 1 0 0 1 1], shape=(128,), dtype=int32)\n",
      "tf.Tensor(\n",
      "[1 1 1 0 0 1 1 1 0 0 1 1 0 1 1 1 0 1 1 0 1 0 0 1 1 0 1 0 1 0 1 1 1 0 0 0 1\n",
      " 0 0 1 0 1 0 1 1 1 1 0 0 1 0 1 1 0 0 1 0 1 1 0 1 0 0 1 0 1 1 1 0 0 1 0 1 1\n",
      " 1 0 1 0 1 1 1 1 1 0 1 0 1 1 1 1 0 0 0 0 1 0 1 0 0 1 0 1 1 1 1 1 0 1 1 0 0\n",
      " 0 1 0 0 1 1 0 1 0 1 0 0 1 0 0 1 1], shape=(128,), dtype=int64)\n",
      "loss:0.351902; acc:1.000000\n",
      "tf.Tensor(\n",
      "[1 0 0 0 1 0 0 1 1 0 1 1 1 1 1 1 0 1 0 1 0 1 1 0 0 0 1 0 1 1 1 1 0 1 0 0 1\n",
      " 1 0 0 0 1 0 0 0 0 1 0 1 0 1 1 1 0 0 0 0 1 1 1 1 0 1 1 1 1 1 0 0 1 1 1 0 1\n",
      " 1 1 1 0 0 1 1 1 1 0 0 1 0 1 1 1 0 0 0 0 0 1 1 1 1 1 1 0 0 1 0 0 1 0 1 1 0\n",
      " 0 0 1 1 1 1 0 0 0 1 0 0 1 1 0 1 1], shape=(128,), dtype=int32)\n",
      "tf.Tensor(\n",
      "[1 0 0 0 1 0 0 1 1 0 1 1 1 1 1 1 0 1 0 1 0 1 1 0 0 0 1 0 1 1 1 1 0 1 0 0 1\n",
      " 1 0 0 0 1 0 0 0 0 1 0 1 0 1 1 1 0 0 0 0 1 1 1 1 0 1 1 1 1 1 0 0 1 1 1 0 1\n",
      " 1 1 1 0 0 1 1 1 1 0 0 1 0 1 1 1 0 0 0 0 0 1 1 1 1 1 1 0 0 1 0 0 1 0 1 1 0\n",
      " 0 0 1 1 1 1 0 0 0 1 0 0 1 1 0 1 1], shape=(128,), dtype=int64)\n",
      "loss:0.345691; acc:1.000000\n",
      "tf.Tensor(\n",
      "[0 0 0 0 1 0 0 1 1 0 0 1 1 1 1 1 1 1 0 0 1 0 1 1 1 1 1 0 0 0 0 0 0 1 1 1 1\n",
      " 0 1 1 0 1 0 1 0 1 1 1 0 0 1 1 0 0 1 0 1 0 0 1 1 0 1 1 0 0 1 0 1 0 1 0 1 1\n",
      " 1 1 0 1 1 0 0 0 0 1 1 1 1 0 1 1 0 0 1 0 0 1 0 1 1 0 1 0 1 1 0 0 0 1 1 0 1\n",
      " 0 0 0 0 1 1 1 0 0 0 1 1 0 0 1 0 0], shape=(128,), dtype=int32)\n",
      "tf.Tensor(\n",
      "[0 0 0 0 1 0 0 1 1 0 0 1 1 1 1 1 1 1 0 0 1 0 1 1 1 1 1 0 0 0 0 0 0 1 1 1 1\n",
      " 0 1 1 0 1 0 1 0 1 1 1 0 0 1 1 0 0 1 0 1 0 0 1 1 0 1 1 0 0 1 0 1 0 1 0 1 1\n",
      " 1 1 0 1 1 0 0 0 0 1 1 1 1 0 1 1 0 0 1 0 0 1 0 1 1 0 1 0 1 1 0 0 0 1 1 0 1\n",
      " 0 0 0 0 1 1 1 0 0 0 1 1 0 0 1 0 0], shape=(128,), dtype=int64)\n",
      "loss:0.338846; acc:1.000000\n"
     ]
    }
   ],
   "source": [
    "import numpy as np\n",
    "import os\n",
    "\n",
    "import tensorflow as tf\n",
    "from tensorflow.keras import Model,layers\n",
    "\n",
    "def preprocess(x,y):\n",
    "    x = tf.io.read_file(x)\n",
    "    x = tf.image.decode_jpeg(x,channels=3)\n",
    "    \n",
    "    x = tf.cast(x,tf.float32) / 255.0\n",
    "    \n",
    "    y = tf.convert_to_tensor(y)\n",
    "    \n",
    "    return x,y\n",
    "\n",
    "def my_face():\n",
    "    path  = os.listdir(\"./my_faces\")\n",
    "    image_path = [os.path.join(\"./my_faces/\",img) for img in path]\n",
    "\n",
    "    return image_path\n",
    "def other_face():\n",
    "    path = os.listdir(\"./other_faces\")\n",
    "    image_path = [os.path.join(\"./other_faces/\",img) for img in path]\n",
    "\n",
    "    return image_path\n",
    "\n",
    "class CNN_WORK(Model):\n",
    "    def __init__(self):\n",
    "        super(CNN_WORK,self).__init__()\n",
    "        self.conv1 = layers.Conv2D(32,kernel_size=5,activation=tf.nn.relu)\n",
    "        self.maxpool1 = layers.MaxPool2D(2,strides=2)\n",
    "        \n",
    "        self.conv2 = layers.Conv2D(64,kernel_size=3,activation=tf.nn.relu)\n",
    "        self.maxpool2 = layers.MaxPool2D(2,strides=2)\n",
    "        \n",
    "        self.flatten = layers.Flatten()\n",
    "        self.fc1 = layers.Dense(1024)\n",
    "        self.dropout = layers.Dropout(rate=0.5)\n",
    "        self.out = layers.Dense(2)\n",
    "    \n",
    "    def call(self,x,is_training=False):\n",
    "        x = self.conv1(x)\n",
    "        x = self.maxpool1(x)\n",
    "        x = self.conv2(x)\n",
    "        x = self.maxpool2(x)\n",
    "        \n",
    "        x = self.flatten(x)\n",
    "        x = self.fc1(x)\n",
    "        x = self.dropout(x,training=is_training)\n",
    "        x = self.out(x)\n",
    "        \n",
    "        \n",
    "        if not is_training:\n",
    "            x = tf.nn.softmax(x)\n",
    "        return x\n",
    "\n",
    "model = CNN_WORK()\n",
    "\n",
    "\n",
    "def cross_entropy_loss(x,y):\n",
    "    y = tf.cast(y,tf.int64)\n",
    "    loss = tf.nn.sparse_softmax_cross_entropy_with_logits(labels=y,logits=x)\n",
    "    return tf.reduce_mean(loss)\n",
    "\n",
    "def accuracy(y_pred,y_true):\n",
    "    correct_pred = tf.equal(tf.argmax(y_pred,1),tf.cast(y_true,tf.int64))\n",
    "    return tf.reduce_mean(tf.cast(correct_pred,tf.float32),axis=-1)\n",
    "\n",
    "optimizer = tf.optimizers.SGD(0.002)\n",
    "\n",
    "def run_optimizer(x,y):\n",
    "    with tf.GradientTape() as g:\n",
    "        pred = model(x,is_training=True)\n",
    "        loss = cross_entropy_loss(pred,y)\n",
    "    training_variabel = model.trainable_variables\n",
    "    gradient = g.gradient(loss,training_variabel)\n",
    "    optimizer.apply_gradients(zip(gradient,training_variabel))\n",
    "    \n",
    "\n",
    "\n",
    "\n",
    "def main():\n",
    "    image_path = my_face().__add__(other_face())\n",
    "    label_my= [1 for i in my_face()]\n",
    "    label_other = [0 for i in other_face()]\n",
    "    label = label_my.__add__(label_other)\n",
    "    data = tf.data.Dataset.from_tensor_slices((image_path,label))\n",
    "    data_loader = data.repeat().shuffle(5000).map(preprocess).batch(128).prefetch(1)\n",
    "    for i in range(2):\n",
    "        for step,(batch_x,batch_y) in enumerate(data_loader.take(128),1):\n",
    "\n",
    "            run_optimizer(batch_x,batch_y)\n",
    "            if step % 20 == 0 :\n",
    "                pred = model(batch_x,is_training=False)\n",
    "                loss = cross_entropy_loss(pred,batch_y)\n",
    "                acc = accuracy(pred,batch_y)\n",
    "                print(batch_y)\n",
    "                a = tf.argmax(pred,1)\n",
    "                print(a)\n",
    "                print(\"loss:%f; acc:%f\"%(loss,acc))\n",
    "main()\n",
    "try:\n",
    "    model.save_weights(\"face_weight\")\n",
    "except:\n",
    "    pass\n",
    "try:\n",
    "    model.save(\"my_face.h5\")\n",
    "except:\n",
    "    pass"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[0]\n"
     ]
    }
   ],
   "source": [
    "## 测试\n",
    "\n",
    "\n",
    "class CNN_WORK(Model):\n",
    "    def __init__(self):\n",
    "        super(CNN_WORK,self).__init__()\n",
    "        self.conv1 = layers.Conv2D(32,kernel_size=5,activation=tf.nn.relu)\n",
    "        self.maxpool1 = layers.MaxPool2D(2,strides=2)\n",
    "        \n",
    "        self.conv2 = layers.Conv2D(64,kernel_size=3,activation=tf.nn.relu)\n",
    "        self.maxpool2 = layers.MaxPool2D(2,strides=2)\n",
    "        \n",
    "        self.flatten = layers.Flatten()\n",
    "        self.fc1 = layers.Dense(1024)\n",
    "        self.dropout = layers.Dropout(rate=0.5)\n",
    "        self.out = layers.Dense(2)\n",
    "    \n",
    "    def call(self,x,is_training=False):\n",
    "       # x = tf.reshape(x,[-1,64,64,3])\n",
    "        \n",
    "        x = self.conv1(x)\n",
    "        x = self.maxpool1(x)\n",
    "        x = self.conv2(x)\n",
    "        x = self.maxpool2(x)\n",
    "        \n",
    "        x = self.flatten(x)\n",
    "        x = self.fc1(x)\n",
    "        x = self.dropout(x,training=is_training)\n",
    "        x = self.out(x)\n",
    "        \n",
    "        \n",
    "        if not is_training:\n",
    "            x = tf.nn.softmax(x)\n",
    "        return x\n",
    "\n",
    "model = CNN_WORK()\n",
    "model.load_weights(\"face_weight\")\n",
    "x = \"./other_faces/.jpg\"\n",
    "x = tf.io.read_file(x)\n",
    "x = tf.image.decode_jpeg(x,channels=3)\n",
    "    \n",
    "x = tf.cast(x,tf.float32) / 255.0\n",
    "x = tf.reshape(x,[-1,64,64,3])\n",
    "y = tf.convert_to_tensor([1])\n",
    "\n",
    "a = model(x)\n",
    "\n",
    "print(tf.argmax(a,axis=1).numpy())\n",
    "    "
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
